package com.bigknow.appstore.server.service;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Service;

import javax.annotation.PreDestroy;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * 提供全局的Timer
 * <p/>
 * Created by 李科风 on 2015/12/8.
 */
@Service
public class ScheduleService extends AbstractFactoryBean<ScheduledExecutorService> {

    private ScheduledExecutorService service = Executors.newScheduledThreadPool(10);

    @Override
    public Class<?> getObjectType() {
        return ScheduledExecutorService.class;
    }

    @Override
    protected ScheduledExecutorService createInstance() throws Exception {
        return service;
    }

    @PreDestroy
    public void destroy() {
        service.shutdown();
    }
}
